package com.aixin.csopsupplier.controller;


import com.aixin.csopsupplier.domain.ServiceDef;
import com.aixin.csopsupplier.model.ServiceDefModel;
import com.aixin.csopsupplier.model.SystemReturn;
import com.aixin.csopsupplier.service.ServiceDefService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/serviceDef")
@EnableAutoConfiguration
public class ServiceDefController {

    @Autowired
    private ServiceDefService serviceDefService;

    @RequestMapping("/getService")
    public List<ServiceDef> getService(ServiceDefModel serviceDefModel){
        return serviceDefService.findAll(serviceDefModel.getServiceName());
    }

    @GetMapping("/services")
    public List<ServiceDef> getSpecServices(@RequestParam(required = false) String supplierID,
                                            @RequestParam String equityID,
                                            @RequestParam String equityLevelID) {
        return serviceDefService.findSpecServices(supplierID, equityID, equityLevelID);
    }

    @GetMapping("/services/supplier/{supplierID}")
    public List<ServiceDef> getSupplierServices(@PathVariable String supplierID) {
        return serviceDefService.findBySupplierID(supplierID);
    }

    @GetMapping("/getService/{customerID}")
    public List<ServiceDef> getCustomerServices(@PathVariable String customerID) {
        return serviceDefService.getCustomerServices(customerID);
    }

    @RequestMapping("/getPageService")
    public Page<ServiceDef> getPageService(ServiceDefModel serviceDefModel, int pageNum, int pageSize){
        return serviceDefService.findAll(serviceDefModel,pageNum,pageSize);
    }

    @RequestMapping("/saveService")
    public SystemReturn saveService(@RequestBody ServiceDefModel serviceDefModel){
        return serviceDefService.save(serviceDefModel);
    }

    @RequestMapping("/updateService")
    public SystemReturn updateService(@RequestBody ServiceDefModel serviceDefModel){
        return serviceDefService.update(serviceDefModel);
    }


}
